package com.campus.activity.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.campus.activity.entity.Feedback;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 反馈评价Mapper接口
 * 
 * @author System
 * @since 2024
 */
@Mapper
public interface FeedbackMapper extends BaseMapper<Feedback> {

    /**
     * 根据活动ID查询反馈列表
     * 
     * @param activityId 活动ID
     * @return 反馈列表
     */
    @Select("SELECT * FROM feedback WHERE activity_id = #{activityId} AND deleted = 0")
    List<Feedback> selectByActivityId(@Param("activityId") Integer activityId);

    /**
     * 根据学生ID查询反馈列表
     * 
     * @param studentId 学生ID
     * @return 反馈列表
     */
    @Select("SELECT * FROM feedback WHERE student_id = #{studentId} AND deleted = 0")
    List<Feedback> selectByStudentId(@Param("studentId") Integer studentId);

    /**
     * 根据活动ID和学生ID查询反馈
     * 
     * @param activityId 活动ID
     * @param studentId 学生ID
     * @return 反馈信息
     */
    @Select("SELECT * FROM feedback WHERE activity_id = #{activityId} AND student_id = #{studentId} AND deleted = 0")
    Feedback selectByActivityIdAndStudentId(@Param("activityId") Integer activityId, 
                                          @Param("studentId") Integer studentId);

    /**
     * 统计活动满意度评分
     * 
     * @param activityId 活动ID
     * @return 统计结果
     */
    @Select("SELECT AVG(satisfaction_score) as avg_score, COUNT(*) as total_count FROM feedback WHERE activity_id = #{activityId} AND satisfaction_score IS NOT NULL AND deleted = 0")
    Map<String, Object> getActivitySatisfactionStats(@Param("activityId") Integer activityId);

    /**
     * 查询未回复的反馈
     * 
     * @param activityId 活动ID
     * @return 未回复的反馈列表
     */
    @Select("SELECT * FROM feedback WHERE activity_id = #{activityId} AND (reply_content IS NULL OR reply_content = '') AND deleted = 0")
    List<Feedback> selectUnrepliedByActivityId(@Param("activityId") Integer activityId);
}